help with number calculation algorithm [hw]

Posted by sa125 on Stack Overflow See other posts from Stack Overflow or by sa125
Published on 2010-03-06T11:58:46Z Indexed on 2010/05/15 20:24 UTC
Read the original article Hit count: 842

Hi -

I'm working on a hw problem that asks me this:

given a finite set of numbers, and a target number, find if the set can be used to calculate the target number using basic math operations (add, sub, mult, div) and using each number in the set exactly once (so I need to exhaust the set). This has to be done with recursion.

So, for example, if I have the set

{1, 2, 3, 4}

and target 10, then I could get to it by using

((3 * 4) - 2)/1 = 10. 

I'm trying to phrase the algorithm in pseudo-code, but so far haven't gotten too far. I'm thinking graphs are the way to go, but would definitely appreciate help on this. thanks.

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about numbers